#!/bin/bash

## start_www_tech.sh: start www_tech app in django fcgi mode
## ljzhou, 2010.08.26

## TODO
#  - executed under deamontools(in method=thread mode), to get
#    (1) controled env (2) 'web' uid (3) monitored process
#  - dormctl.sh script(nginx+django?), just as apachectl

APP_DIR="/usr/share/nginx/www"
CFG_DIR="/infoware/_conf/www_tech"

PYTHON="/usr/bin/python2.7"
DJANGO_ADMIN="/usr/local/bin/django-admin.py"
#PYTHON="/opt/python/bin/python2"
#DJANGO_ADMIN="/usr/lib/python2.4/site-packages/django/bin/django-admin.py"

############### no config below this line ##################
#export PYTHONPATH="$PYTHONPATH:$CFG_DIR"
export PYTHONPATH="$PYTHONPATH:$APP_DIR:/home/litbsvc/py"
# mysettings.py in $CFG_DIR
#export DJANGO_SETTINGS_MODULE=mysettings
export DJANGO_SETTINGS_MODULE=settings

umask 027

## server: self daemonized, total num=20 with 10 threads each
## Help message:   help
## TCP socket  :   host=... port=...
PIDFILE="/tmp/django.pid"
if [ -f $PIDFILE ]; then
    kill `cat -- $PIDFILE`
    rm -f -- $PIDFILE
    sleep 3
fi

$PYTHON $DJANGO_ADMIN \
    runfcgi daemonize=true method=prefork \
    maxspare=5 minspare=2 maxchildren=10 maxrequests=500 \
    socket="/tmp/www_tech.sock" pidfile=$PIDFILE \
    umask=000 debug=true \
    --pythonpath=$APP_DIR

# EOF: start_www_tech.sh
